package cn.yyx.orderservice.service.impl;

import cn.yyx.orderservice.entity.Order;
import cn.yyx.orderservice.entity.OrderPageVo;
import cn.yyx.orderservice.entity.OrderQueryPageParam;
import cn.yyx.orderservice.mapper.OrderMapper;
import cn.yyx.orderservice.service.OrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sun
 * @since 2023-10-25
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Override
    public HashMap<String, Object> list(OrderQueryPageParam param) {
        //这一行是干嘛的。创建一个分页对象，
        Page<OrderPageVo> page = new Page<>(param.getPage(), param.getLimit());
        // 查询的时候传入，mybatis, 会自动帮我们完成分页
        List<OrderPageVo> records = baseMapper.listOrder(page, param);
//        //这一行呢 records 把我们查询出来的数据放到这里面，到时候前端从里面取就行了
//        page.setRecords(records);
        // 总条数(这个是mybatis给我们统计好的，直接拿就行)
        long total = page.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("items", records);
        map.put("total", total);
        return map;
    }
}
